﻿using ETA.IRepository;
using ETA.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ETA.Service
{
    public class FileTypeService : IFileTypeService
    {

        #region 属性

        private IFileTypeRepository _IFileTypeRepository { set; get; }


        #endregion

        #region 构造函数

        public FileTypeService(IFileTypeRepository IFileTypeRepository)
        {
            _IFileTypeRepository = IFileTypeRepository;
        }

        #endregion

        public QueryFileTypeResponse QueryFileType(QueryFileTypeRequest req)
        {
            var res = new QueryFileTypeResponse();
            try
            {
                if (!string.IsNullOrEmpty(req.FileTypeId))
                {
                    res.FileTypeList = _IFileTypeRepository.GetAllList(b => b.FileTypeId == req.FileTypeId);
                }
                else if (!string.IsNullOrEmpty(req.FileTypeName))
                {
                    res.FileTypeList = _IFileTypeRepository.GetAllList(b => b.FileTypeName == req.FileTypeName);
                }
                else
                {
                    res.FileTypeList = _IFileTypeRepository.GetAllList();
                }
                res.Result.IsSuccess = true;
            }
            catch (Exception e)
            {
                res.Result.IsSuccess = false;
                res.Result.ErrMessage = e.Message;
            }
            return res;
        }
    }
}
